package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.DamageListGoodsService;
import com.atguigu.jxc.service.OverflowListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/overflowListGoods")
public class OverflowListGoodsController {

    @Autowired
    private OverflowListGoodsService overflowListGoodsServic ;

    @PostMapping("/save")
    public ServiceVO save(HttpServletRequest request, OverflowList overflowList , String overflowListGoodsStr, @RequestParam(required = false) String overflowNumber) {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("currentUser");
        overflowList.setOverflowNumber(overflowNumber);
        overflowList.setUserId(user.getUserId());
        List<OverflowListGoods> damageListGoods = JSON.parseArray(overflowListGoodsStr, OverflowListGoods.class);
        overflowListGoodsServic.save(overflowList,damageListGoods);
        return new ServiceVO(100, "成功");
    }

    @PostMapping("/list")
    public Map<String,Object> list(String  sTime, String  eTime){
        return overflowListGoodsServic.list(sTime,eTime);
    }

    @PostMapping("/goodsList")
    public Map<String,Object>  goodsList(Integer overflowListId){
        return overflowListGoodsServic.goodsList(overflowListId);
    }
}
